package com.enjoy.solr.comp;

import org.apache.lucene.document.Document;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.Query;
import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.search.DocIterator;
import org.apache.solr.search.DocList;
import org.apache.solr.search.SolrIndexSearcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;

public class CorrectComponent extends SearchComponent {

	public static final String COMPONENT_NAME = "correct";

	private static final Logger logger = LoggerFactory
			.getLogger(CorrectComponent.class);

	@Override
	public void prepare(ResponseBuilder rb) throws IOException {

	}

	@Override
	public void process(ResponseBuilder rb) throws IOException {

		if (rb.getSortSpec() != null && rb.getSortSpec().getSort() != null) {
			return;
		}

		DocList docList = rb.getResults().docList;
		DocIterator it = docList.iterator();

		SolrIndexSearcher searcher = rb.req.getSearcher();
		// 获取检索组件
		SearchComponent component = rb.req.getCore().getSearchComponent(
				QueryComponent.COMPONENT_NAME);

		// 纠错
		if (it.hasNext()) {
			Document doc = searcher.doc(it.nextDoc());

		}
	}

	@Override
	public String getDescription() {
		return "correctComponent ...";
	}

	@Override
	public String getSource() {
		return null;
	}

}
